package com.mvc.framework.listener;

import com.mvc.framework.entity.XmlBean;
import com.mvc.framework.utils.StrutsConfig;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Map;

public class ActionListener implements ServletContextListener {

	public void contextInitialized(ServletContextEvent sce) {
		ServletContext context = sce.getServletContext();
		String xmlPath = context.getInitParameter("struts-config");
		String tomcatPath = context.getRealPath("\\");
		System.out.println("开始加载struts配置...");
		try {
			Map<String, XmlBean> strutsConfigMap = StrutsConfig.readStrutsXml(tomcatPath + xmlPath);
			context.setAttribute("strutsConfig", strutsConfigMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("加载struts配置完成");
	}

	public void contextDestroyed(ServletContextEvent sce) {
		System.out.println("信息：系统已注销！");
	}
}
